<?php

//********************************
//	File:		request.php
//	Author:		Philip Pryce
//	Date:		
//	Comments:	
//********************************


class Request {
	
	var $qs;
	var $controller;
	var $function;
	var $segments;
	
	var $class = '';
	
	function __construct () {
		
		$this->parse();
		
	}
	
	function parse () {
		
		$SM = getInstance();
		
		$this->qs = $_SERVER['QUERY_STRING'];
		$this->segments = explode('/', $this->qs);
		$this->controller = (isset($this->segments[0]) && !empty($this->segments[0]) ? $this->segments[0] : $SM->config->get('default_controller'));
		$this->function = (isset($this->segments[1]) && !empty($this->segments[1]) ? $this->segments[1] : $SM->config->get('default_function'));
		
		if (file_exists(APP . 'controllers/' . $this->controller . '.php')) {
			require_once(APP . 'controllers/' . $this->controller . '.php');
		}
		
		$classname = ucfirst($this->controller);
		
		if (!class_exists($classname)) {
			 displayError(ERROR_FATAL, 'Request->parse', 'Class "' . $classname . '" doesnt exist in "' . APP . 'controllers/' . $this->controller . '.php"');
		}
		
		$this->class = new $classname();
		
		$this->class->{$this->function}();
		
		unset($SM);
		return;
		
	}
	
}

?>